<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Rails::Generator::Base</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Rails::Generator::Base</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/railties/lib/rails_generator/base_rb.html">
                vendor/rails/railties/lib/rails_generator/base.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
The base code generator is bare-bones. It sets up the source and
destination paths and tells the logger whether to keep its trap shut.
</p>
<p>
It&#8216;s useful for copying files such as stylesheets, images, or
javascripts.
</p>
<p>
For more comprehensive template-based passive code generation with
arguments, you&#8216;ll want <a
href="NamedBase.html">Rails::Generator::NamedBase</a>.
</p>
<p>
Generators create a <a href="Base.html#M001888">manifest</a> of the actions
they perform then hand the <a href="Base.html#M001888">manifest</a> to a
command which replays the actions to do the heavy lifting (such as checking
for existing files or creating directories if needed). Create, destroy, and
list commands are included. Since a single <a
href="Base.html#M001888">manifest</a> may be used by any command, creating
<a href="Base.html#M001887">new</a> generators is as simple as writing some
code templates and declaring what you&#8216;d like to do with them.
</p>
<p>
The <a href="Base.html#M001888">manifest</a> method must be implemented by
subclasses, returning a <a
href="Manifest.html">Rails::Generator::Manifest</a>. The <tt><a
href="Base.html#M001891">record</a></tt> method is provided as a
convenience for <a href="Base.html#M001888">manifest</a> creation. Example:
</p>
<pre>
  class StylesheetGenerator &lt; Rails::Generator::Base
    def manifest
      record do |m|
        m.directory('public/stylesheets')
        m.file('application.css', 'public/stylesheets/application.css')
      end
    end
  end
</pre>
<p>
See <a href="Commands/Create.html">Rails::Generator::Commands::Create</a>
for a list of methods available to the <a
href="Base.html#M001888">manifest</a>.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001892">banner</a>&nbsp;&nbsp;
      <a href="#M001890">destination_path</a>&nbsp;&nbsp;
      <a href="#M001888">manifest</a>&nbsp;&nbsp;
      <a href="#M001887">new</a>&nbsp;&nbsp;
      <a href="#M001891">record</a>&nbsp;&nbsp;
      <a href="#M001889">source_path</a>&nbsp;&nbsp;
      <a href="#M001893">usage_message</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Options.html">Options</a></span>
      </div>
    </div>

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">args</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">destination_root</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">source_root</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001887" class="method-detail">
        <a name="M001887"></a>

        <div class="method-heading">
          <a href="#M001887" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(runtime_args, runtime_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001887-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001887-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/base.rb, line 101</span>
101:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">runtime_args</span>, <span class="ruby-identifier">runtime_options</span> = {})
102:         <span class="ruby-ivar">@args</span> = <span class="ruby-identifier">runtime_args</span>
103:         <span class="ruby-identifier">parse!</span>(<span class="ruby-ivar">@args</span>, <span class="ruby-identifier">runtime_options</span>)
104: 
105:         <span class="ruby-comment cmt"># Derive source and destination paths.</span>
106:         <span class="ruby-ivar">@source_root</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:source</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">spec</span>.<span class="ruby-identifier">path</span>, <span class="ruby-value str">'templates'</span>)
107:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:destination</span>]
108:           <span class="ruby-ivar">@destination_root</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:destination</span>]
109:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-operator">::</span><span class="ruby-constant">RAILS_ROOT</span>
110:           <span class="ruby-ivar">@destination_root</span> = <span class="ruby-operator">::</span><span class="ruby-constant">RAILS_ROOT</span>
111:         <span class="ruby-keyword kw">end</span>
112: 
113:         <span class="ruby-comment cmt"># Silence the logger if requested.</span>
114:         <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">quiet</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:quiet</span>]
115: 
116:         <span class="ruby-comment cmt"># Raise usage error if help is requested.</span>
117:         <span class="ruby-identifier">usage</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:help</span>]
118:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001890" class="method-detail">
        <a name="M001890"></a>

        <div class="method-heading">
          <a href="#M001890" class="method-signature">
          <span class="method-name">destination_path</span><span class="method-args">(relative_destination)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return the full path from the destination root for the given path. Example
for destination_root = &#8217;/dest&#8217;:
</p>
<pre>
  destination_path('some/path.rb') == '/dest/some/path.rb'
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001890-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001890-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/base.rb, line 153</span>
153:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destination_path</span>(<span class="ruby-identifier">relative_destination</span>)
154:         <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">destination_root</span>, <span class="ruby-identifier">relative_destination</span>)
155:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001888" class="method-detail">
        <a name="M001888"></a>

        <div class="method-heading">
          <a href="#M001888" class="method-signature">
          <span class="method-name">manifest</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Generators must provide a <a href="Base.html#M001888">manifest</a>. Use the
<tt><a href="Base.html#M001891">record</a></tt> method to create a <a
href="Base.html#M001887">new</a> <a href="Base.html#M001888">manifest</a>
and <a href="Base.html#M001891">record</a> your generator&#8216;s actions.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001888-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001888-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/base.rb, line 122</span>
122:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">manifest</span>
123:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-node">&quot;No manifest for '#{spec.name}' generator.&quot;</span>
124:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001889" class="method-detail">
        <a name="M001889"></a>

        <div class="method-heading">
          <a href="#M001889" class="method-signature">
          <span class="method-name">source_path</span><span class="method-args">(relative_source)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return the full path from the source root for the given path. Example for
source_root = &#8217;/source&#8217;:
</p>
<pre>
  source_path('some/path.rb') == '/source/some/path.rb'
</pre>
<p>
The given path may include a colon &#8217;:&#8217; character to indicate
that the file belongs to another generator. This notation allows any
generator to borrow files from another. Example:
</p>
<pre>
  source_path('model:fixture.yml') = '/model/source/path/fixture.yml'
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001889-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001889-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/base.rb, line 134</span>
134:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">source_path</span>(<span class="ruby-identifier">relative_source</span>)
135:         <span class="ruby-comment cmt"># Check whether we're referring to another generator's file.</span>
136:         <span class="ruby-identifier">name</span>, <span class="ruby-identifier">path</span> = <span class="ruby-identifier">relative_source</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">':'</span>, <span class="ruby-value">2</span>)
137: 
138:         <span class="ruby-comment cmt"># If not, return the full path to our source file.</span>
139:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">nil?</span>
140:           <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">source_root</span>, <span class="ruby-identifier">name</span>)
141: 
142:         <span class="ruby-comment cmt"># Otherwise, ask our referral for the file.</span>
143:         <span class="ruby-keyword kw">else</span>
144:           <span class="ruby-comment cmt"># FIXME: this is broken, though almost always true.  Others'</span>
145:           <span class="ruby-comment cmt"># source_root are not necessarily the templates dir.</span>
146:           <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">lookup</span>(<span class="ruby-identifier">name</span>).<span class="ruby-identifier">path</span>, <span class="ruby-value str">'templates'</span>, <span class="ruby-identifier">path</span>)
147:         <span class="ruby-keyword kw">end</span>
148:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M001892" class="method-detail">
        <a name="M001892"></a>

        <div class="method-heading">
          <a href="#M001892" class="method-signature">
          <span class="method-name">banner</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Override with your own usage <a href="Base.html#M001892">banner</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001892-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001892-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/base.rb, line 164</span>
164:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">banner</span>
165:           <span class="ruby-node">&quot;Usage: #{$0} #{spec.name} [options]&quot;</span>
166:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001891" class="method-detail">
        <a name="M001891"></a>

        <div class="method-heading">
          <a href="#M001891" class="method-signature">
          <span class="method-name">record</span><span class="method-args">() {|m| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convenience method for generator subclasses to <a
href="Base.html#M001891">record</a> a <a
href="Base.html#M001888">manifest</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001891-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001891-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/base.rb, line 159</span>
159:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">record</span>
160:           <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generator</span><span class="ruby-operator">::</span><span class="ruby-constant">Manifest</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">m</span> }
161:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001893" class="method-detail">
        <a name="M001893"></a>

        <div class="method-heading">
          <a href="#M001893" class="method-signature">
          <span class="method-name">usage_message</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Read USAGE from file in generator base path.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001893-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001893-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/base.rb, line 169</span>
169:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">usage_message</span>
170:           <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">spec</span>.<span class="ruby-identifier">path</span>, <span class="ruby-value str">'USAGE'</span>)) <span class="ruby-keyword kw">rescue</span> <span class="ruby-value str">''</span>
171:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>